package com.cw.jeeyt.controller.facade.format;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cw.jeeyt.service.bo.facade.format.ApiFormatBo;
import com.cw.jeeyt.service.bo.facade.format.ApiFormatRespBo;
import com.cw.jeeyt.api.dto.response.JsonResultDto;
import com.cw.jeeyt.service.facade.format.ApiFormatService;

/**
 * 格式化工具
 *
 * @author chenw
 * @date 2020/12/4
 */
@Controller
@RequestMapping("/apiFormat")
public class ApiFormatController {
    private static final Logger logger = LoggerFactory.getLogger(ApiFormatController.class);
    @Autowired
    private ApiFormatService apiFormatService;
    @RequestMapping("/xml")
    public ModelAndView xml(){
        return new ModelAndView("api/apiFormatXml_form");
    }
    @RequestMapping("/json")
    public ModelAndView json(){

        return new ModelAndView("api/apiFormatJson_form");
    }
    @RequestMapping("/ymltransproperties")
    public ModelAndView ymltransproperties(){

        return new ModelAndView("api/apiYmlTransProperties_form");
    }
    @RequestMapping("/formatData")
    public JsonResultDto formatData(ApiFormatBo apiFormatBo){
        JsonResultDto jsonResultDto = new JsonResultDto(false);
        try{
            ApiFormatRespBo respBo = apiFormatService.formatData(apiFormatBo);
            jsonResultDto.setSuccess(true);
            jsonResultDto.setData(respBo);
        }catch (Exception e){
            logger.error("格式化数据出错:",e);
            jsonResultDto.setMsg("格式化数据出错:" + e.getMessage());
        }
        return jsonResultDto;
    }
}
